<link href="__ADMIN__/css/juncms.min2.css?v=1" rel="stylesheet" type="text/css" />  
<style>
#demo input[type=checkbox], #demo  input[type=radio], #demo select {display: initial;}
.layui-tree-branch,.layui-tree-leaf{display: none}
.layui-tree-skin-as input{display: none}

.layui-tree li .layui-tree-spread, .layui-tree li a{height: 25px;font-size: 12px;}
.layui-tree li a cite{font-size: 12px}
.org-tree li {line-height: 25px;}
.btn+.btn:not(.btn-block) {margin-left: 0;}
</style>


<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	
	<!-- END RIBBON -->
	<div class="content">
		<div class="panel panel-default panel-intro">
			<div class="panel-heading">
				<div class="panel-lead">
					<em>
						地区管理
					</em>
					点击左侧菜单，可以查询出下级城市。
				</div>
			</div>
			<div class="panel-body">
				<div id="myTabContent" class="tab-content">
					<div class="tab-pane fade active in" id="one">
						<div class="widget-body no-padding">
							<div class="bootstrap-table">


                                    <div class="org-left-col tray-cell j_depa" style="float:left;margin-right: 10px">
                                        <div class="org-left-header">
                                            <span class="tab">
                                                <a id="organization-users" class="router j_user active">
                                                    地区列表
                                                </a>
                                            </span>
                                        </div>
                                        <a id="show-first-group" class="hide router">
                                        </a>
                                        <div id="org-tree" class="org-tree scrollwrapper mCustomScrollbar _mCS_24 mCS_no_scrollbar">
                                            <div id="mCSB_24" class="mCustomScrollBox mCS-darkblue mCSB_vertical_horizontal mCSB_inside" >
                                                <div id="mCSB_24_container_wrapper">
                                                    <div id="mCSB_24_container" class="mCSB_container" style="position: relative; top: 0px; left: 0px; width: 100%; overflow: hidden; overflow-y: auto" >
                                                        <div id="org-tree-list" class="mt-15">
                                                                 
                                                                    
                                                        </div>
                                                        
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>



								<div class="fixed-table-toolbar" style="width:-webkit-calc(100% - 310px); width:-moz-calc(100% - 310px); width:calc(100% - 310px);float: left;">
									<div class="bs-bars pull-left">
										<div id="toolbar" class="toolbar">
											<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新">
												<i class="fa fa-refresh"></i>
                                            </a>
                                            {if condition="$adminController->vif('region','add')"}
											<a href="javascript:add('{:url('region/add')}');" class="btn btn-success btn-add" title="添加">
												<i class="fa fa-plus"></i> 添加
                                            </a>
                                            {/if}
										</div>
									</div>
									<div class="columns columns-right btn-group pull-right">
										
										<div class="keep-open btn-group" title="列">
											<button type="button" aria-label="columns" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
												<i class="glyphicon glyphicon-th icon-th"></i>
												<span class="caret"></span>
											</button>
											<ul class="dropdown-menu" id="table_menu">
												
											</ul>
										</div>
                                        
									</div>
								</div>
								<div class="fixed-table-container" style="width:-webkit-calc(100% - 310px); width:-moz-calc(100% - 310px); width:calc(100% - 310px);float: left;">
									<div class="fixed-table-body">
										
										<table id="table" class="table table-striped table-bordered table-hover"
										data-operate-edit="1" data-operate-del="1" width="100%">
											<thead>
												<tr>
                                                    <th data-status="1"><div class="th-inner">ID</div></th>
                                                    <th data-status="1"><div class="th-inner">地区代码</div></th>
                                                    <th data-status="1"><div class="th-inner">地区名称</div></th>
                                                    <th data-status="1"><div class="th-inner">操作</div></th>
                                                </tr>
                                                
											</thead>
											<tbody id="userlistCon">
                                                {volist name="list" id="v"}
                                                <tr class="del-{$v.r_id}">
                                                    <td align="center">{$v.r_id}</td>
                                                    <td align="center">{$v.r_code}</td>
                                                    <td align="center">{$v.r_name}</td>
                                                    <td align="center">
                                                        {if condition="$adminController->vif('region','add')"}
                                                        <a href="javascript:add('{:url('region/add', ['pid'=>$v['r_id']])}');" class="btn btn-xs btn-success btn-add" title="添加">
                                                            <i class="fa fa-plus"></i>
                                                        </a>
                                                        {/if}
                                                    
                                                        {if condition="$adminController->vif('region','upd')"}
                                                        <a href="javascript:upd('{:url('region/upd', ['pid'=>$v['r_id']])}');" class="btn btn-xs btn-success btn-editone" title="编辑">
                                                            <i class="fa fa-pencil"></i>
                                                        </a>
                                                        {/if}
                                                        {if condition="$adminController->vif('region','del')"}
                                                        <button data-id="{$v.r_id}" class="btn btn-xs btn-danger btn-delone del_role" title="删除">
                                                            <i class="fa fa-trash"></i>
                                                        </button>
                                                        {/if}
                                                    </td>
                                                </tr>
                                                {/volist}
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

		
<script type="text/javascript">
layui.use(['tree','layer'], function(){
	// 地区节点树
	layui.tree({
		elem: '#org-tree-list' //指定元素
		,target: '_blank' //是否新选项卡打开（比如节点返回href才有效）
		,click: function(item){ //点击节点回调
            var id   = item.id;
            var name = item.name;
            console.log(item);
            $.ajax({
                type: 'post',
                data:{'id':id},
                url: "{:url('region/index')}",
                success: function(data) {
                    var array = eval(data);
                    var html = '';
                    for(var i=0; i<array.length; i++){
                        html += '<tr class="del-'+array[i]['r_id']+'">';
                        html += '<td align="center">'+array[i]['r_id']+'</td>';
                        html += '<td align="center">'+array[i]['r_code']+'</td>';
                        html += '<td align="center">'+array[i]['r_name']+'</td>';
                        html += '<td align="center">';
                        {if condition="$adminController->vif('region','add')"}
                        html += "<a href=javascript:add('{:url('region/add')}?pid="+array[i]['r_id']+"'); class='btn btn-xs btn-success btn-add' title='添加'>";
                        html += '<i class="fa fa-plus"></i>';
                        html += '</a>&nbsp;';
                        {/if}
                    
                        {if condition="$adminController->vif('region','upd')"}
                        html += "<a href=javascript:add('{:url('region/upd')}?pid="+array[i]['r_id']+"'); class='btn btn-xs btn-success btn-editone' title='编辑'>";
                        html += '<i class="fa fa-pencil"></i>';
                        html += '</a>&nbsp;';
                        {/if}
                        {if condition="$adminController->vif('region','del')"}
                        html += '<button data-id="'+array[i]['r_id']+'" class="btn btn-xs btn-danger btn-delone del_role" title="删除">';
                        html += '<i class="fa fa-trash"></i>';
                        html += '</button>';
                        {/if}
                        html += '</td>';
                        html += '</tr>';
                        
                    }
                    $('#userlistCon').html(html);
                    // 监听删除
                    $(".del_role").on('click', function(){
                        if (confirm('确认删除吗')) {
                            var id   = $(this).attr('data-id');
                            var data = {'id':id};
                            region_del(data);
                        }
                    });
                }
            });

		}
		,nodes: {$json} //节点
    });
});


// 添加
function add(href) {
	layer.open({
		type: 2,
		title: '添加新地区',
		shadeClose: true,
		shade: false,
		maxmin: true,
		area: ['700px', '80%'],
		btn: ['确认', '取消'],
		content: href,
		yes: function(index, layero) {
			var _this = layero.find('iframe')[0];
			var bool  = _this.contentWindow.doSubimt();
			if (bool !== false) {
				$.thinkmimi({Content : bool['msg'],Type : 1,Align:'right',OutTime:2000,});
				menu_run();
				layer.closeAll();
				window.setTimeout(function(){
					window.location.reload();
				}, 700);
			}
		},
	});
}
// 修改
function upd(href) {
	layer.open({
		type: 2,
		title: '修改地区',
		shadeClose: true,
		shade: false,
		maxmin: true,
		area: ['700px', '80%'],
		btn: ['确认', '取消'],
		content: href,
		yes: function(index, layero) {
			var _this = layero.find('iframe')[0];
			var bool  = _this.contentWindow.doSubimt();
			if (bool !== false) {
				$.thinkmimi({Content : bool['msg'],Type : 1,Align:'right',OutTime:2000,});
				menu_run();
				layer.closeAll();
				window.setTimeout(function(){
					window.location.reload();
				}, 700);
			}
		},
	});
}
// 删除
$(".del_role").on('click', function(){
    if (confirm('确认删除吗')) {
        var id   = $(this).attr('data-id');
        var data = {'id':id};
        region_del(data);
    }
});
function region_del(data) {
    $.ajax({
        type: 'post',
        data:data,
        url: "{:url('del')}",
        success: function(data) {
            var array = eval('('+data+')');
            if (array['code'] == '01') {
                $.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:2000});
            } else {
                $.thinkmimi({Content : array['msg'], Type:1, Align:'right', OutTime:2000});
                $('.del-'+array['data']).remove();
            }
        }
    });
}
</script>

